<?php

//策略模式

//定义接口
interface Math
{
   public function calce($op1,$op2);
}

//实现接口
class MatchAdd implements Math
{
  public function calce($op1,$op2)
  {
     return $op1+$op2;
  }
}

class MatchSub implements Math
{
  public function calce($op1,$op2)
  {
     return $op1-$op2;
  }
}


//创建一个计算器
class Cmath{

protected $cacl=null;

public function __construct($type)
{
	$cacl='Match'.$type;
	$this->cacl=new $cacl();
}

public function cacle($op1,$op2)
{
   return $this->cacl->calce($op1,$op2);
}

}

$type='sub';
$obj=new Cmath($type);
echo $obj->cacle(5,3);


